//
//  CommunityDetailTableViewCell.m
//  PTravel
//
//  Created by dllo on 15/11/23.
//  Copyright © 2015年 李涵. All rights reserved.
//

#import "CommunityDetailTableViewCell.h"

@implementation CommunityDetailTableViewCell

- (void)dealloc
{
    [_image release];
    [_userName release];
    [_top release];
    [_time release];
    [_commentImage release];
    [_replys release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{
    
    self.image = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 46, 46)];
    self.image.layer.masksToBounds = YES;
    self.image.layer.cornerRadius = 23;
    self.image.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.image];
    [_image release];
    
    self.userName = [[UILabel alloc] initWithFrame:CGRectMake(self.image.frame.origin.x+self.image.frame.size.width+10, 20, 200, 20)];
    self.userName.font = [UIFont systemFontOfSize:14];
    self.userName.text = @"asdasf";
    //self.userName.backgroundColor = [UIColor blueColor];
    [self addSubview:self.userName];
    [_userName release];
    
    self.top = [[UILabel alloc] initWithFrame:CGRectMake(BOUNDS.size.width-40, self.userName.frame.origin.y, 26, 15)];
    self.top.backgroundColor = [UIColor cyanColor];
    self.top.text = @"置顶";
    self.top.hidden = YES;
    self.top.font = [UIFont systemFontOfSize:12];
    self.top.textColor = [UIColor whiteColor];
    self.top.layer.masksToBounds = YES;
    self.top.layer.cornerRadius = 3;
    [self addSubview:self.top];
    [_top release];
    
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(self.userName.frame.origin.x, self.userName.frame.origin.y+self.userName.frame.size.height, BOUNDS.size.width-self.userName.frame.origin.x-10, 36)];
    //self.title.backgroundColor = [UIColor yellowColor];
    self.title.font = [UIFont systemFontOfSize:14];
    self.title.textAlignment = 0;
    [self addSubview:self.title];
    [_title release];
    
    self.commentImage = [[UIImageView alloc] initWithFrame:CGRectMake(BOUNDS.size.width-50, self.title.frame.origin.y+self.title.frame.size.height+10, 15, 15)];
    self.commentImage.image = [UIImage imageNamed:@"iconfont-pinglun.png"];
    [self addSubview:self.commentImage];
    
    self.replys = [[UILabel alloc] initWithFrame:CGRectMake(self.commentImage.frame.origin.x+18, self.title.frame.origin.y+self.title.frame.size.height+10, 40, 15)];
    self.replys.textColor = [UIColor colorWithRed:0.454 green:1.000 blue:0.500 alpha:1.000];
    self.replys.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.replys];
    
    self.time = [[UILabel alloc] initWithFrame:CGRectMake(self.title.frame.origin.x+5, self.replys.frame.origin.y, 200, 15)];
    self.time.text = @"2014-04-04";
    self.time.font = [UIFont systemFontOfSize:13];
    self.time.textColor = [UIColor colorWithWhite:0.599 alpha:1.000];
    [self addSubview:self.time];
}

- (void)setTheme:(Theme *)theme
{
    if (_theme != theme) {
        [_theme release];
        _theme = [theme retain];
    }
    if (theme.is_top == true) {
        self.top.hidden = NO;
    }else{
        self.top.hidden = YES;
    }
    self.replys.text = theme.replys;
    self.title.text = theme.title;
    self.userName.text = theme.username;
    self.title.numberOfLines = 2;
    CGFloat height =  [AppTools heightForContent:self.title.text font:14.0 width:BOUNDS.size.width-self.userName.frame.origin.x-10];
    CGRect tempFrame = self.title.frame;
    tempFrame.size.height = height;
    self.title.frame = tempFrame;
    //时间戳转标准时间
    self.time.text = [AppTools timestampExchange:theme.publish_time];
    NSURL *url = [NSURL URLWithString:theme.avatar];
    [self.image sd_setImageWithURL:url placeholderImage:IMAGE];
    
    self.title.textColor = TEXTCOLOR;
    self.userName.textColor = TEXTCOLOR;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
